import getSysTaskList from '../lib/System/getSysTaskList';
import getPidUsage from '../lib/System/getPidUsage';
import netWorkMana from '../lib/System/netWorkMana';
import getDeviceList from '../lib/System/getDeviceList';
import startEXE from '../lib/System/startEXE';
import router from 'koa-router';
import getServerInfo from '../lib/System/getServerInfo';
import getWlanInfo from '../lib/System/getWlanInfo';
import getBatteryReport from '../lib/System/getBatteryReport';
import getCPUUsage from '../lib/System/getCPUUsage';
import getGPUUsage from '../lib/System/getGPUUsage';
import getMemoryUsage from '../lib/System/getMemoryUsage';

const WindowsInfo = new router({prefix: '/WindowsInfo'});

WindowsInfo
    .get('/getServerInfo', async (ctx: any) => {
        ctx.set('content-type', 'application/json;charset=utf-8');
        ctx.set('sis-format', 'on');
        ctx.body = {
            code: 200,
            message: '成功获取计算机基本信息',
            data: await getServerInfo()
        };
    })
    .get('/getSysTaskList', async (ctx: any) => {
        ctx.set('content-type', 'application/json;charset=utf-8');
        ctx.set('sis-format', 'on');
        ctx.body = {
            code: 200,
            message: '成功获取操作系统进程的任务列表',
            data: await getSysTaskList()
        };
    })
    .get('/getPidUsage', async (ctx: any) => {
        ctx.set('content-type', 'application/json;charset=utf-8');
        ctx.set('sis-format', 'on');
        const pid = ctx.request.query.pid;
        ctx.body = {
            code: 200,
            message: '线程的使用率-' + pid,
            data: await getPidUsage(Number(pid) || 0)
        };
    })
    .get('/getNetworkList', async (ctx: any) => {
        ctx.set('content-type', 'application/json;charset=utf-8');
        ctx.set('sis-format', 'on');
        ctx.body = {
            code: 200,
            message: '获取设备网络列表',
            data: await netWorkMana.getRecently()
        };
    })
    .get('/startEXE', async (ctx: any) => {
        const exePath = ctx.request.query.exePath;
        ctx.set('content-type', 'application/json;charset=utf-8');
        ctx.set('sis-format', 'on');
        ctx.body = {
            code: 200,
            message: '启动EXE',
            data: await startEXE(exePath)
        };
    })
    .get('/getDeviceList', async (ctx: any) => {
        ctx.set('content-type', 'application/json;charset=utf-8');
        ctx.set('sis-format', 'on');
        ctx.body = {
            code: 200,
            message: '计算机的设备列表',
            data: await getDeviceList()
        };
    })
    .get('/getCPUUsage', async (ctx: any) => {
        ctx.set('content-type', 'application/json;charset=utf-8');
        ctx.set('sis-format', 'on');
        ctx.body = {
            code: 200,
            message: '获取CPU的占用率',
            data: await getCPUUsage()
        };
    })
    .get('/getGPUUsage', async (ctx: any) => {
        ctx.set('content-type', 'application/json;charset=utf-8');
        ctx.set('sis-format', 'on');
        ctx.body = {
            code: 200,
            message: '获取GPU的占用率',
            data: await getGPUUsage()
        };
    })
    .get('/getMemoryUsage', async (ctx: any) => {
        ctx.set('content-type', 'application/json;charset=utf-8');
        ctx.set('sis-format', 'on');
        ctx.body = {
            code: 200,
            message: '获取内存的占用率',
            data: await getMemoryUsage()
        };
    })
    .get('/getBatteryReport', async (ctx: any) => {
        ctx.set('content-type', 'application/json;charset=utf-8');
        ctx.set('sis-format', 'on');
        ctx.body = {
            code: 200,
            message: '获取电池报告',
            data: await getBatteryReport()
        };
    })
    .get('/getWlanInfo', async (ctx: any) => {
        ctx.set('content-type', 'application/json;charset=utf-8');
        ctx.set('sis-format', 'on');
        ctx.body = {
            code: 200,
            message: '无线网络连接状态',
            data: await getWlanInfo()
        };
    });

export default WindowsInfo;